/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tester.java
 *
 * Created on Feb 22, 2011, 12:15:43 PM
 */

package gui;

import handler.*;
import java.security.*;
import java.awt.Rectangle;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;

import parser.LexError;
import parser.ParseError;
import parser.Parser;
import exprtree.Expr;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import javax.swing.JButton;
/**
 *
 * @author Matt
 */
public class Notebook extends javax.swing.JFrame {
    
    public String fileToOpen;
    
    public Notebook() {
        initCustomComponents();
        initComponents();
        this.showEquations(new ArrayList<EquateNode>());
    }
    private void initCustomComponents(){
        signedin = false;
        fileloaded = false;
        filelocal = true;
        loggedinuser = new User();
        graphingFrame = new javax.swing.JFrame();
        graphingFrame.setSize(400, 400);
        graphingFrame.setResizable(false);
        graph = new GraphComponent();
        graphingFrame.add(graph);
        graphingFrame.pack();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        AddEquationFrame = new javax.swing.JFrame();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        fileChooser = new javax.swing.JFileChooser();
        DESEncryptPasswordDialog = new javax.swing.JDialog();
        DESPasswordField1 = new javax.swing.JPasswordField();
        DESPasswordField2 = new javax.swing.JPasswordField();
        DESOkButton = new javax.swing.JButton();
        DESEnterPasswordLabel = new javax.swing.JLabel();
        DESReenterPasswordLabel = new javax.swing.JLabel();
        DESEncryptPasswordOptionPane = new javax.swing.JOptionPane();
        jLabel4 = new javax.swing.JLabel();
        textField1 = new java.awt.TextField();
        textField2 = new java.awt.TextField();
        delTanPtsButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tanPtsList = new javax.swing.JList();
        addEndPtsButton = new javax.swing.JButton();
        tanPtTextBox = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        endPtsList = new javax.swing.JList();
        addTanPtsButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        toTextBox = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        delEndPtsButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        equationList = new javax.swing.JList();
        delEqButton = new javax.swing.JButton();
        fromTextBox = new javax.swing.JTextField();
        addEquationButton = new javax.swing.JButton();
        addEquationTextBox = new javax.swing.JTextField();
        equationLabel = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        MainMenu = new javax.swing.JMenu();
        LoadNotebookMenuItem = new javax.swing.JMenuItem();
        saveLocalMenuItem = new javax.swing.JMenuItem();
        ExitMenuItem = new javax.swing.JMenuItem();
        CloudMenu = new javax.swing.JMenu();
        LoadFromCloudMenuItem = new javax.swing.JMenuItem();
        SavetoCloudMenuItem = new javax.swing.JMenuItem();
        ChangePermissionsMenuItem = new javax.swing.JMenuItem();
        SignInMenuItem = new javax.swing.JMenuItem();

        jButton1.setText("sin");

        jButton2.setText("cos");

        jButton3.setText("tan");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("sqrt");

        jButton5.setText("Add Equation");

        jButton6.setText("Cancel");

        jScrollPane4.setViewportView(jTextPane1);

        javax.swing.GroupLayout AddEquationFrameLayout = new javax.swing.GroupLayout(AddEquationFrame.getContentPane());
        AddEquationFrame.getContentPane().setLayout(AddEquationFrameLayout);
        AddEquationFrameLayout.setHorizontalGroup(
            AddEquationFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AddEquationFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(AddEquationFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(AddEquationFrameLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4))
                    .addGroup(AddEquationFrameLayout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton6))
                    .addComponent(jScrollPane4))
                .addContainerGap())
        );
        AddEquationFrameLayout.setVerticalGroup(
            AddEquationFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AddEquationFrameLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(AddEquationFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(AddEquationFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        fileChooser.addChoosableFileFilter(new DESFilter());
        fileChooser.addChoosableFileFilter(new ZIPFilter());
        fileChooser.addChoosableFileFilter(new XMLFilter());
        fileChooser.setAcceptAllFileFilterUsed(false);

        DESEncryptPasswordDialog.setTitle("Set password");
        DESEncryptPasswordDialog.setAlwaysOnTop(true);
        DESEncryptPasswordDialog.setMinimumSize(new java.awt.Dimension(312, 157));
        DESEncryptPasswordDialog.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                DESEncryptPasswordDialogFocusLost(evt);
            }
        });

        DESPasswordField1.setToolTipText("Type a password in");
        DESPasswordField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        DESPasswordField1.setNextFocusableComponent(DESPasswordField2);

        DESPasswordField2.setToolTipText("Verify the password here");

        DESOkButton.setText("OK");
        DESOkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DESOkButtonActionPerformed(evt);
            }
        });

        DESEnterPasswordLabel.setText("Enter a Password");

        DESReenterPasswordLabel.setText("Reenter Password");

        javax.swing.GroupLayout DESEncryptPasswordDialogLayout = new javax.swing.GroupLayout(DESEncryptPasswordDialog.getContentPane());
        DESEncryptPasswordDialog.getContentPane().setLayout(DESEncryptPasswordDialogLayout);
        DESEncryptPasswordDialogLayout.setHorizontalGroup(
            DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DESEncryptPasswordDialogLayout.createSequentialGroup()
                .addContainerGap(85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, DESEncryptPasswordDialogLayout.createSequentialGroup()
                        .addGap(134, 134, 134)
                        .addComponent(DESOkButton, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(DESEncryptPasswordDialogLayout.createSequentialGroup()
                        .addGroup(DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(DESReenterPasswordLabel)
                            .addComponent(DESEnterPasswordLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(DESPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(DESPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(27, 27, 27))
        );
        DESEncryptPasswordDialogLayout.setVerticalGroup(
            DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DESEncryptPasswordDialogLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(DESEnterPasswordLabel)
                    .addComponent(DESPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DESEncryptPasswordDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DESPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DESReenterPasswordLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DESOkButton)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        DESEncryptPasswordOptionPane.setMessage(DESPasswordField1);

        jLabel4.setText("jLabel4");

        textField1.setText("textField1");

        textField2.setText("textField2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Equation Notebook"); // NOI18N
        setResizable(false);

        delTanPtsButton.setText("Delete Tan Point");
        delTanPtsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delTanPtsButtonActionPerformed(evt);
            }
        });

        tanPtsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {};
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(tanPtsList);

        addEndPtsButton.setText("Add End Points");
        addEndPtsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addEndPtsButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Point");

        endPtsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {};
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        endPtsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                endPtsListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(endPtsList);

        addTanPtsButton.setText("Add Tan Point");
        addTanPtsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTanPtsButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("b ");

        jLabel1.setText("a");

        delEndPtsButton.setText("Delete Points");
        delEndPtsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delEndPtsButtonActionPerformed(evt);
            }
        });

        equationList.setModel(new javax.swing.AbstractListModel() {

            String[] equationArray = new String[0];

            String[] strings = equationArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        equationList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                equationListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(equationList);

        delEqButton.setText("Delete Equation");
        delEqButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delEqButtonActionPerformed(evt);
            }
        });

        addEquationButton.setText("Add Equation");
        addEquationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addEquationButtonActionPerformed(evt);
            }
        });

        equationLabel.setText("Equation");

        MainMenu.setText("File");
        MainMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MainMenuActionPerformed(evt);
            }
        });

        LoadNotebookMenuItem.setText("Load Equation Notebook");
        LoadNotebookMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadNotebookMenuItemActionPerformed(evt);
            }
        });
        MainMenu.add(LoadNotebookMenuItem);

        saveLocalMenuItem.setText("Save Local File");
        saveLocalMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveLocalMenuItemActionPerformed(evt);
            }
        });
        MainMenu.add(saveLocalMenuItem);

        ExitMenuItem.setText("Exit");
        ExitMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ExitMenuItemMouseClicked(evt);
            }
        });
        ExitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitMenuItemActionPerformed(evt);
            }
        });
        MainMenu.add(ExitMenuItem);

        jMenuBar1.add(MainMenu);

        CloudMenu.setLabel("Cloud");
        CloudMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloudMenuActionPerformed(evt);
            }
        });

        LoadFromCloudMenuItem.setText("Load from Cloud");
        LoadFromCloudMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadFromCloudMenuItemActionPerformed(evt);
            }
        });
        CloudMenu.add(LoadFromCloudMenuItem);

        SavetoCloudMenuItem.setText("Save to  Cloud");
        SavetoCloudMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SavetoCloudMenuItemActionPerformed(evt);
            }
        });
        CloudMenu.add(SavetoCloudMenuItem);

        ChangePermissionsMenuItem.setText("Change Permissions");
        ChangePermissionsMenuItem.setToolTipText("Change the permissions for users of this file");
        ChangePermissionsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ChangePermissionsMenuItemActionPerformed(evt);
            }
        });
        CloudMenu.add(ChangePermissionsMenuItem);

        SignInMenuItem.setText("Sign In");
        SignInMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SignInMenuItemActionPerformed(evt);
            }
        });
        CloudMenu.add(SignInMenuItem);

        jMenuBar1.add(CloudMenu);
        CloudMenu.getAccessibleContext().setAccessibleName("CloudMenu");

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addEquationButton, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(equationLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(addEquationTextBox, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE))
                    .addComponent(delEqButton, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(fromTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(toTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(delEndPtsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(addEndPtsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(tanPtTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(addTanPtsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(delTanPtsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(toTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tanPtTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addComponent(addTanPtsButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(addEquationTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(equationLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(fromTextBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addEquationButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addEndPtsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(delTanPtsButton)
                        .addComponent(delEndPtsButton))
                    .addComponent(delEqButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void delTanPtsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delTanPtsButtonActionPerformed
        // TODO add your handling code here:
        
        String[] endPoints = endPtsList.getSelectedValue().toString().split(",");
        equationHandler.deletePoint(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0]), Double.valueOf(endPoints[1]), Double.valueOf(tanPtsList.getSelectedValue().toString()));
        tanPtsList.setModel(new javax.swing.AbstractListModel() {

            String[] endPoints = endPtsList.getSelectedValue().toString().split(",");

            String[] tanPtArray = equationHandler.retrievePointsAsString(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0].trim()), Double.valueOf(endPoints[1].trim()));

            int k = 0;




            String[] strings = tanPtArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
            });
    }//GEN-LAST:event_delTanPtsButtonActionPerformed

    private void delEqButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delEqButtonActionPerformed
        // TODO add your handling code here:
        
        
        equationHandler.deleteEquation(equationList.getSelectedValue().toString());
        equationList.setModel(new javax.swing.AbstractListModel() {

            String[] equationArray = equationHandler.retrieveEquations();

            String[] strings = equationArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        endPtsList.setModel(new DefaultListModel());
        tanPtsList.setModel(new DefaultListModel());

    }//GEN-LAST:event_delEqButtonActionPerformed

    private void tanPtsListValueChanged(ListSelectionEvent evt) {
    	if(equationList.getSelectedIndex() >= 0 && endPtsList.getSelectedIndex() >= 0  && tanPtsList.getSelectedIndex() >= 0){
    		
        	String tanString = tanPtsList.getSelectedValue().toString();
        	double tanX = 0.0;
        	try{
        		tanX = Double.parseDouble(tanString);
			} catch (Exception e) {
				
			}

			graph.setTanX(tanX);
			graph.setShowTan(true);
			try{
				graph.setExpression(equationList.getSelectedValue().toString());
			}catch(LexError e){
				JOptionPane.showMessageDialog(this, e.getMessage(), "LexicalError", JOptionPane.ERROR_MESSAGE);
			}catch(ParseError e){
				JOptionPane.showMessageDialog(this, e.getMessage(), "ParsingError", JOptionPane.ERROR_MESSAGE);
			}
			graphingFrame.setVisible(true);
			graph.repaint(new Rectangle(graph.width, graph.height));
		}
    	else{
    		graph.setShowTan(false);
    	}
		
	}
    
    private void equationListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_equationListValueChanged
        endPtsList.clearSelection();
        tanPtsList.clearSelection();
        tanPtsList.removeAll();

        if(equationList.getSelectedIndex() >= 0){
        endPtsList.setModel(new javax.swing.AbstractListModel() {
            
            String[] intervalArray = equationHandler.retrieveIntervalsAsString(equationList.getSelectedValue().toString());

            int k = 0;
            
            String[] strings = intervalArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        tanPtsList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {};

            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
            });

        }
    }//GEN-LAST:event_equationListValueChanged

    private void endPtsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_endPtsListValueChanged
        
        tanPtsList.clearSelection();
        if(equationList.getSelectedIndex() >= 0 && endPtsList.getSelectedIndex() >= 0 ){

        	String[] endPoints = endPtsList.getSelectedValue().toString().split(",");
            double a = Double.valueOf(endPoints[0].trim());
            double b = Double.valueOf(endPoints[1].trim());
            graph.setAB(a , b);
            try{
				graph.setExpression(equationList.getSelectedValue().toString());
			}catch(LexError e){
				JOptionPane.showMessageDialog(this, e.getMessage(), "LexicalError", JOptionPane.ERROR_MESSAGE);
			}catch(ParseError e){
				JOptionPane.showMessageDialog(this, e.getMessage(), "ParsingError", JOptionPane.ERROR_MESSAGE);
			}
            graphingFrame.setVisible(true);
            graph.repaint(new Rectangle(graph.width, graph.height));
            
        tanPtsList.setModel(new javax.swing.AbstractListModel() {
            
            String[] endPoints = endPtsList.getSelectedValue().toString().split(",");
            
            String[] tanPtArray = equationHandler.retrievePointsAsString(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0].trim()), Double.valueOf(endPoints[1].trim()));

            int k = 0;

            String[] strings = tanPtArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
            });
        }

    }//GEN-LAST:event_endPtsListValueChanged

    private void addEquationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEquationButtonActionPerformed
		try {
			Parser parser = new Parser();
			Expr e = parser.parse(addEquationTextBox.getText());
			equationHandler.saveEquation(addEquationTextBox.getText());
			equationList.setModel(new javax.swing.AbstractListModel() {

				String[] equationArray = equationHandler.retrieveEquations();

				String[] strings = equationArray;

				public int getSize() {
					return strings.length;
				}

				public Object getElementAt(int i) {
					return strings[i];
				}
			});
			endPtsList.setModel(new DefaultListModel());
			tanPtsList.setModel(new DefaultListModel());
		} catch (LexError e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "LexicalError",
					JOptionPane.ERROR_MESSAGE);
		} catch (ParseError e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "ParsingError",
					JOptionPane.ERROR_MESSAGE);
		}
    	
    }//GEN-LAST:event_addEquationButtonActionPerformed

    private void ExitMenuItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMenuItemMouseClicked
       
    }//GEN-LAST:event_ExitMenuItemMouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void MainMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MainMenuActionPerformed
        

       
    }//GEN-LAST:event_MainMenuActionPerformed

    private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitMenuItemActionPerformed
        // TODO add your handling code here:
         System.exit(1);
    }//GEN-LAST:event_ExitMenuItemActionPerformed

    private void addEndPtsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEndPtsButtonActionPerformed
        if(fromTextBox.getText().compareTo("") != 0 && toTextBox.getText().compareTo("") != 0){

        double a = Double.valueOf(fromTextBox.getText());
        double b = Double.valueOf(toTextBox.getText());
        
        fromTextBox.setText("");
        toTextBox.setText("");
        
        if(a < b){

        equationHandler.saveInterval(equationList.getSelectedValue().toString(), a, b);
        endPtsList.setModel(new javax.swing.AbstractListModel() {

            String[] intervalArray = equationHandler.retrieveIntervalsAsString(equationList.getSelectedValue().toString());

            int k = 0;
            String[] strings = intervalArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        tanPtsList.setModel(new DefaultListModel());
        }
        else {
        	JOptionPane.showMessageDialog(this, "b must be greater than a");
        }
        }
        

        
    }//GEN-LAST:event_addEndPtsButtonActionPerformed

    private void addTanPtsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTanPtsButtonActionPerformed
        int selectedIndex = endPtsList.getSelectedIndex();
        if (selectedIndex == -1) {
            selectedIndex = 0;
        }
        
        String[] endPoints = endPtsList.getModel().getElementAt(selectedIndex).toString().split(",");
        
        equationHandler.savePoint(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0]), Double.valueOf(endPoints[1]), Double.valueOf(tanPtTextBox.getText()));
        tanPtTextBox.setText("");
        tanPtsList.setModel(new javax.swing.AbstractListModel() {
            
            String[] endPoints = endPtsList.getSelectedValue().toString().split(",");

            String[] tanPtArray = equationHandler.retrievePointsAsString(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0].trim()), Double.valueOf(endPoints[1].trim()));

            int k = 0;
            String[] strings = tanPtArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
            });
    }//GEN-LAST:event_addTanPtsButtonActionPerformed

    private void delEndPtsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delEndPtsButtonActionPerformed
        String[] endPoints = endPtsList.getSelectedValue().toString().split(",");
        equationHandler.deleteInterval(equationList.getSelectedValue().toString(), Double.valueOf(endPoints[0]), Double.valueOf(endPoints[1]));
        endPtsList.setModel(new javax.swing.AbstractListModel() {

            String[] intervalArray = equationHandler.retrieveIntervalsAsString(equationList.getSelectedValue().toString());

            int k = 0;

            String[] strings = intervalArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        tanPtsList.setModel(new DefaultListModel());
    }//GEN-LAST:event_delEndPtsButtonActionPerformed

    private void LoadNotebookMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadNotebookMenuItemActionPerformed
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();

        String filename = file.getName();
        
        if (filename.endsWith(".xml")) {
            this.dao = new XMLDAO(filename);
        }
        else if (filename.endsWith(".gz")) {
            this.dao = new CompressedXMLDAO(filename);
        } else if (filename.endsWith(".des")) {
            
                javax.swing.JPasswordField despassword = new javax.swing.JPasswordField();
                final javax.swing.JComponent[] inputs = new javax.swing.JComponent[] {
                new javax.swing.JLabel("Enter the password"), despassword
                };
                JOptionPane.showMessageDialog(null, inputs, "Authenticate", JOptionPane.PLAIN_MESSAGE);

                String password = new String(despassword.getPassword());

            this.dao = new CompressedEncryptedXMLDAO(filename,password);
        } else {
            throw new IllegalArgumentException("Must specify an xml, des, or gz file.");
        }
        
        this.showEquations(this.dao.getEquations());
        fileloaded = true;
        filelocal = true;
    }
    }//GEN-LAST:event_LoadNotebookMenuItemActionPerformed

    /**
     * Shows the specified equations in the GUI.
     * @param equations equations to show
     */
    private void showEquations(List<EquateNode> equations) {
        this.equationHandler = new EquationNodeHandler(equations);
        
        equationList.setModel(new javax.swing.AbstractListModel() {

            String[] equationArray = equationHandler.retrieveEquations();

            String[] strings = equationArray;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        tanPtsList.setModel(new DefaultListModel());
        endPtsList.setModel(new DefaultListModel());  
    }
    
    private void saveLocalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveLocalMenuItemActionPerformed


        int returnVal = fileChooser.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            String filename = file.getName();

            if (filename.endsWith(".xml")) {
                this.dao = new XMLDAO(filename);
            }
            else if (filename.endsWith(".gz")) {
                this.dao = new CompressedXMLDAO(filename);
            } else if (filename.endsWith(".des")) {
                
               // Pops up a dialog box with two passwords to confirm - Jed

                javax.swing.JPasswordField despassword1 = new javax.swing.JPasswordField();
                javax.swing.JPasswordField despassword2 = new javax.swing.JPasswordField();
                final javax.swing.JComponent[] inputs = new javax.swing.JComponent[] {
                new javax.swing.JLabel("Input a password"), despassword1,
                new javax.swing.JLabel("Verify password"),  despassword2
                };
                JOptionPane.showMessageDialog(null, inputs, "Password Set", JOptionPane.PLAIN_MESSAGE);
                if (new String(despassword1.getPassword()).equals(new String(despassword2.getPassword()))){
                String password = new String(despassword1.getPassword());
                //System.out.println("\n\nPass " + password);
                this.dao = new CompressedEncryptedXMLDAO(filename,password);
                }else{
                    //passwords are not the same
                    MessageBox("Passwords are not the same", "Error - Password");
                    return;
                }
            } else {
                throw new IllegalArgumentException("Must specify an xml, des, or gz file.");
            }
            
            this.dao.saveEquations(this.equationHandler.getEquations());
        }
    }//GEN-LAST:event_saveLocalMenuItemActionPerformed

    private void DESOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DESOkButtonActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_DESOkButtonActionPerformed

    private void DESEncryptPasswordDialogFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_DESEncryptPasswordDialogFocusLost
     
    }//GEN-LAST:event_DESEncryptPasswordDialogFocusLost

    private void LoadFromCloudMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadFromCloudMenuItemActionPerformed
        
       // String loadResponse;
        
        // TODO add your handling code here:
        if (signedin == true){
        //CloudOpenPanel cloudOpenPanel = new CloudOpenPanel(loggedinuser.getId(),this);
        //cloudOpenPanel.setVisible(true);
        
        
        
//        String filename = null;
//        while(filename == null) {
//            filename = cloudOpenPanel.fileToOpen;
//        }
//        System.out.println("SDFSF" + filename);
            
    JFrame frame = new JFrame("Load Menu");
    JButton button = new JButton ("Load Files");
    ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
       Component source = (Component)actionEvent.getSource();
        Object response = JOptionPane.showInputDialog(
          source,
          "Which file would you like to open",
          "Select File",
          JOptionPane.QUESTION_MESSAGE,
          null,
          getFiles(),
          "db");
        System.out.println ("Response: " + response);
        
        DBDAO dao = new DBDAO(20, loggedinuser.getId(), (String)response, loggedinuser.getUserPassword());
        showEquations(dao.getEquations());
        //String[] equationArray = equationHandler.retrieveEquations();
        
        //this.dao = new DBDAO(20, loggedinuser.getId(), response, loggedinuser.getUserPassword());
       // this.showEquations(this.dao.getEquations());
        
        }
    };
    button.addActionListener(actionListener);
    Container contentPane = frame.getContentPane();
   contentPane.add(button, BorderLayout.SOUTH);
   frame.setSize(300, 200);
   frame.setVisible(true);
  }




       // this.dao = new DBDAO(20, loggedinuser.getId(), response, loggedinuser.getUserPassword());
        //this.showEquations(this.dao.getEquations());

        //somehow set filelocal = false;
       
    }//GEN-LAST:event_LoadFromCloudMenuItemActionPerformed
private String[] getFiles() {
        DBHandler dbh = new DBHandler();
        ArrayList<NotebookFile> al = dbh.getAllNotebookFilesFromUser( loggedinuser.getId());
        String[] s = new String[al.size()];

        for(int i = 0; i < al.size(); i++) {
            s[i] = al.get(i).getNotebookFileName();
        }
        return s;
    }
    private void CloudMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloudMenuActionPerformed
        // TODO do nothing and I'm too lazy to remove it - Jed
    }//GEN-LAST:event_CloudMenuActionPerformed

    private void SavetoCloudMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SavetoCloudMenuItemActionPerformed
        String filename = "";
        int fileID = -1;
        boolean namechanged = false;

        javax.swing.JTextField dbfilename = new javax.swing.JTextField();

        final javax.swing.JComponent[] dbinputs = new javax.swing.JComponent[] {
        new javax.swing.JLabel("File Name"), dbfilename
        };


        if (signedin == true && fileloaded ==true){
            if (filelocal == true){
                //the origin of this file is local, make new db entry
                //EncryptionHandler h = new EncryptionHandler();
                    //build Notebookfile
               // NotebookFile nb = new NotebookFile(String name, byte[] zip, int owner, int lockedBy);
               // NotebookFile nb = new NotebookFile("", this.equationHandler.getEquations(), loggedinuser.getId(), -1);
            }else{
            //the origin of this file is from the cloud, get the Notebook info
            //Notebook file should be set, only save if user has permissions
            //and file is not locked by another user
                dbfilename.setText(currentnotebook.getNotebookFileName());
                fileID = currentnotebook.getId();
            }
            int retval = JOptionPane.showConfirmDialog(null, dbinputs, "Save to Cloud", JOptionPane.OK_CANCEL_OPTION);
            if (retval == JOptionPane.OK_OPTION){
                if (filelocal == false && !dbfilename.getText().equals(currentnotebook.getNotebookFileName())){namechanged = true;}
                filename = dbfilename.getText();

                this.dao = new DBDAO(fileID, loggedinuser.getId(), filename , loggedinuser.getUserPassword());
                this.dao.saveEquations(this.equationHandler.getEquations());

                DBHandler dbh = new DBHandler();
                ArrayList<NotebookFile> n = dbh.getNotebookFileByNotebookFileName(filename);
                currentnotebook = n.get(0);
                //add initial permissions if this is a new file in db
                if (namechanged == true || filelocal ==true){
               // handler.Permissions p = new handler.Permissions(currentnotebook.getId(), loggedinuser.getId(), 0, rsakey.getPublic().getEncoded());
                //dbh.addNewPermission(p);
                filelocal = false;
                }
                //System.out.println("saved file");
                //System.out.println(p.toString());
                //System.out.println(rsakey.getPublic().toString());
                //System.out.println(currentnotebook.toString());
            }
           
         
        //need to build three cases: open or created locally
       // CloudSavePanel cloudSavePanel = new CloudSavePanel();
       // cloudSavePanel.setVisible(true);
        }
    }//GEN-LAST:event_SavetoCloudMenuItemActionPerformed

    private void SignInMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SignInMenuItemActionPerformed
        //Sign in the user
        javax.swing.JTextField username = new javax.swing.JTextField();
        javax.swing.JPasswordField despassword = new javax.swing.JPasswordField();
        final javax.swing.JComponent[] inputs = new javax.swing.JComponent[] {
        new javax.swing.JLabel("User name"), username,
        new javax.swing.JLabel("Password"),  despassword
        };
        JOptionPane.showMessageDialog(null, inputs, "Sign In", JOptionPane.PLAIN_MESSAGE);

        String password = new String(despassword.getPassword());

        DBHandler db = new DBHandler();
        ArrayList<User> userlist = new ArrayList<User>();
        userlist = db.getUsersByName(username.getText());
       // System.out.println(userlist.size());
        if (userlist.size() == 0){
            //add new user dialog, done here so I can get inputs back easier
            javax.swing.JTextField dbusername = new javax.swing.JTextField();
            javax.swing.JTextField dbemail = new javax.swing.JTextField();
            javax.swing.JPasswordField dbdespassword = new javax.swing.JPasswordField();
            dbusername.setText(username.getText());
            final javax.swing.JComponent[] dbinputs = new javax.swing.JComponent[] {
            new javax.swing.JLabel("User name"), dbusername,
            new javax.swing.JLabel("Email"), dbemail,
            new javax.swing.JLabel("Password"),  dbdespassword
            };
            int retval = JOptionPane.showConfirmDialog(null, dbinputs, "Create New User", JOptionPane.OK_CANCEL_OPTION);

            //only add if ok button is clicked
            if (retval==JOptionPane.OK_OPTION){
                String newuser = dbusername.getText();
                String email = dbemail.getText();
                String pass = new String(dbdespassword.getPassword());

                EncryptionHandler rsa = new EncryptionHandler();
                rsakey = rsa.createKeys(pass);


       try{
        File f=new File("p.dat");
        FileOutputStream fop=new FileOutputStream(f);

      if(f.exists()){

          fop.write(rsakey.getPrivate().getEncoded());

          fop.flush();
          fop.close();
          MessageBox("title","The key has been written");
          } else{
            MessageBox("Horror Error", "This file is not exist");
          }
       }catch (Exception e){

       }

                User user = new User(newuser , pass, email , rsakey.getPublic().getEncoded());
                db.addNewUser(user);
            }
        }else{
            //Each username must be unique
            //Log them in if they have the right password
            if (password.equals(userlist.get(0).getUserPassword())){
                    loggedinuser= userlist.get(0);
                    EncryptionHandler rsa = new EncryptionHandler();
                    rsakey = rsa.createKeys(loggedinuser.getUserPassword());
                    signedin = true;
                    this.setTitle("Signed in as: " + loggedinuser.getUserName());
            }else{
                MessageBox("Wrong password","You have entered the wrong password");
            }
        }
    }//GEN-LAST:event_SignInMenuItemActionPerformed

    private void ChangePermissionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChangePermissionsMenuItemActionPerformed
        // TODO add your handling code here:
        if (signedin == true && filelocal==false){
             CloudChangePermissions cld = new CloudChangePermissions(currentnotebook);
             cld.setVisible(true);
        }else{
            MessageBox("Error","Either user not signed in,\n or file not registered");
        }
    }//GEN-LAST:event_ChangePermissionsMenuItemActionPerformed
    private void MessageBox(String title, String message){
        final javax.swing.JComponent[] inputsmsg = new javax.swing.JComponent[] {
        new javax.swing.JLabel(message)
        };
        JOptionPane.showMessageDialog(null, inputsmsg, title, JOptionPane.PLAIN_MESSAGE);
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Notebook().setVisible(true);
            }
        });
    }
    
    private NotebookDAO dao;
    private EquationNodeHandler equationHandler;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame AddEquationFrame;
    private javax.swing.JMenuItem ChangePermissionsMenuItem;
    private javax.swing.JMenu CloudMenu;
    private javax.swing.JDialog DESEncryptPasswordDialog;
    private javax.swing.JOptionPane DESEncryptPasswordOptionPane;
    private javax.swing.JLabel DESEnterPasswordLabel;
    private javax.swing.JButton DESOkButton;
    private javax.swing.JPasswordField DESPasswordField1;
    private javax.swing.JPasswordField DESPasswordField2;
    private javax.swing.JLabel DESReenterPasswordLabel;
    private javax.swing.JMenuItem ExitMenuItem;
    private javax.swing.JMenuItem LoadFromCloudMenuItem;
    private javax.swing.JMenuItem LoadNotebookMenuItem;
    private javax.swing.JMenu MainMenu;
    private javax.swing.JMenuItem SavetoCloudMenuItem;
    private javax.swing.JMenuItem SignInMenuItem;
    private javax.swing.JButton addEndPtsButton;
    private javax.swing.JButton addEquationButton;
    private javax.swing.JTextField addEquationTextBox;
    private javax.swing.JButton addTanPtsButton;
    private javax.swing.JButton delEndPtsButton;
    private javax.swing.JButton delEqButton;
    private javax.swing.JButton delTanPtsButton;
    private javax.swing.JList endPtsList;
    private javax.swing.JLabel equationLabel;
    private javax.swing.JList equationList;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JTextField fromTextBox;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JMenuItem saveLocalMenuItem;
    private javax.swing.JTextField tanPtTextBox;
    private javax.swing.JList tanPtsList;
    private java.awt.TextField textField1;
    private java.awt.TextField textField2;
    private javax.swing.JTextField toTextBox;
    // End of variables declaration//GEN-END:variables


    private GraphComponent graph;
    private JFrame graphingFrame;
    private boolean signedin;
    private boolean fileloaded;
    private boolean filelocal;
    private User loggedinuser;
    private KeyPair rsakey;
    private NotebookFile currentnotebook;
    public String loadResponse;
}
